﻿Imports Aricie.DNN.UI.Controls
Imports Lucene.Net.Search
Imports Aricie.ComponentModel
Imports Aricie.DNN.Modules.LuceneSearch.Logs
Imports Aricie.DNN.Modules.LuceneSearch.Settings
Imports Aricie.DNN.Settings
Imports DotNetNuke.Services.Localization
Imports Aricie.DNN.Modules.LuceneSearch.Business
Imports Aricie.DNN.Modules.LuceneSearch.ModuleProviders
Imports Aricie.DNN.Services

Namespace Aricie.DNN.Modules.LuceneSearch.UI

    'Public Enum TemplateType
    '    Result
    '    Details
    'End Enum

    Public MustInherit Class LuceneModuleBase
        Inherits AriciePortalModuleBase

        Private _LuceneResultsSettings As LuceneResultsSettings

        Public ReadOnly Property LuceneResultsSettings() As LuceneResultsSettings
            Get
                If _LuceneResultsSettings Is Nothing Then
                    Me._LuceneResultsSettings = _
                        Aricie.DNN.Settings.GetModuleSettings(Of LuceneResultsSettings)(SettingsScope.ModuleSettings, Me.ModuleId)
                End If
                Return Me._LuceneResultsSettings
            End Get
        End Property


        Protected Overloads Function GetItemTemplate(ByVal searchResult As LuceneSearchResultsInfo, ByVal TemplateType As String) As String
            Dim TemplateContext = New Global.Configuration.Templating.Context.DNNTemplatingContext(TemplateType)

            If LuceneResultsSettings.TemplateConfiguration.UseLocalizedTemplates Then
                TemplateContext.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture.ToString() ' le langage courant est fixé par DNN en fonction de l'url
            End If

            If LuceneResultsSettings.TemplateConfiguration.UseModuleBasedTemplates Then
                If searchResult.ModuleName <> "" Then
                    TemplateContext.Content = searchResult.ModuleName
                    TemplateContext.ContentDisplayName = searchResult.FriendlyModuleName
                Else
                    TemplateContext.Content = searchResult.ProviderName
                    TemplateContext.ContentDisplayName = searchResult.ProviderName
                End If
            End If

            Return Global.Configuration.Templating.TemplateProvider.Usage.GetValue(New Global.Configuration.Templating.Scope.ModuleScope(PortalId, ModuleId), TemplateContext)

        End Function

    End Class

End Namespace


